<template>
	<yd-flexbox>
		<ul>
			<li v-for="item,key in addressdata" :key="key" @click="returnAdd(item.cityid)">
				<!--<router-link to="/">-->
				<img v-if="item.icon.indexOf('?')==-1" :src="item.icon+'?imageslim'" />
				<img v-else :src="item.icon" />
				<p>{{item.ShortName}}</p>
				<!--</router-link>-->
			</li>
		</ul>
	</yd-flexbox>
</template>

<script>
	import { mapGetters, mapActions } from 'vuex'
	import api from '../fetch/api'
	export default {
		name: 'Myaddress',
		data() {
			var that = this;
			return {
				pageid: that.$route.params.pageid,
				addressdata: [],
				isaddcity: true
			}
		},
		mounted() {
			var that = this;
			that.address();
		},
		computed: {
			...mapGetters([
				'source'
			])
		},
		methods: {
			returnAdd(city) {
				var that = this;
				if(that.pageid == 0) {
					sessionStorage.setItem("cityId", city);
					sessionStorage.setItem("isaddcity", true);
					that.$router.push({
						path: '/',
						query: {
							isaddcity: that.isaddcity,
							cityId: city
						}
					})
				} else {

					that.$router.push({
						path: '/search',
						query: {
							isaddcity: that.isaddcity,
							cityId: city,
							city: true
						}
					})

				}
			},
			address() {
				var that = this;
				var ajaxSign = {
					"source": that.source,
				};
				let ajaxData = api.getAES(ajaxSign);
				//				数据调用
				api.GetAddress(ajaxData)
					.then(res => {
						let ajaxdata = res.result;
						that.addressdata = ajaxdata;
					})
			}
		},
		beforeRouteLeave(to, from, next) {
			// 设置下一个路由的 meta
			to.meta.keepAlive = false; // 让 A 不缓存，即刷新
			next();
		}
	}
</script>

<style scoped>
	ul {
		display: -webkit-flex;
		display: flex;
		padding: .2rem;
		box-sizing: border-box;
	}
	
	img {
		max-width: .92rem;
	}
	
	li {
		text-align: center;
		margin-right: .34rem;
	}
</style>